What are virtual and pure virtual functions?
What are virtual and pure virtual functions?
607
23-Aug-2021
Ashutosh Kumar Verma
26-Aug-2021Virtual Function - Virtual function is member function of class. It is declare with ' virtual' keyword in base class and also we provide its definition in same class. It is access in derived class by using 'override' keyword to change its statements as requirement. Virtual function can not declare in abstract class and can be instantiate that base class which contain virtual method. All virtual methods may or may not be redefined derived class.
Pure Virtual function - Pure virtual function is like a virtual function defines with 'virtual' keyword in the base class. It has no definition in same class. Pure virtual function is declare in base class with assigning 0(zero). In which class it declared that class is abstract class so that class can not be instantiate. All pure virtual function will must redefined in derived class to provide its body.
Output- Pure Virtual function is override